<?php defined( '_MAXSITE' ) or die( 'Restricted access' );
CheckAdmin($admin_user, $admin_pwd);
$option = $_GET['option'];
?>
<style type="text/css">
    #form_lr label{display: block;width: 50%;float: left;}
    #form_lr input[type="text"]{margin-left: 20px;}
    input{padding: 4px 8px 4px 8px;}
</style>
<?php
$db->connectdb(DB_NAME,DB_USERNAME,DB_PASSWORD);
if(empty($option))
{
?>
<table cellSpacing=0 cellPadding=0 width=820 border=0>
    <tr>
        <td width="10" vAlign=top>
            <img src="images/fader.gif" border=0>
        </td>
        <td width="810" vAlign=top>
            <img src="images/topfader.gif" border=0><br/>
        <!-- Admin -->
        <img src="images/menu/textmenu_admin.gif" border="0"><br/>
        <table width="800" align=center cellSpacing=0 cellPadding=0 border=0>
            <tr>
                <td height="1" class="dotline"></td>
            </tr>
            <tr>
                <td>
                    <b>
                        <img src="images/icon/plus.gif" border="0" align="absmiddle">
                        <a href="?name=admin&file=main">
                            <?php echo _ADMIN_GOBACK;?>
                        </a>
                    </b>
                    <div id="form_lr">
                        <?php
                        $sql = "SELECT *"
                            ." FROM web_exchange";
                        $res = mysql_query($sql);
                        $obj = mysql_fetch_object($res);
                        ?>
                    <form name="adinForm" method="post" action="index.php?name=admin&file=exchange&option=update_exchange">
                        <label for="sell_lr">ราคาขาย:
                            <input type="text" name="sell_lr" id="sell_lr" value="<?php echo $obj->sell_lr?>" />
                        </label>
                        
                        
                        <label for="sell_lr_result">จำนวนที่มีขาย:
                            <input type="text" name="sell_lr_result" id="sell_lr_result" value="<?php echo $obj->sell_lr_result?>" />
                        </label>
                        
                        
                        <label for="buy_lr">ราคารับซื้อ:
                            <input type="text" name="buy_lr" id="buy_lr" value="<?php echo $obj->buy_lr?>" />
                        </label>
                        
                        
                        <label for="buy_lr_result">จำนวนที่รับซื้อ:สมาชิก:วัน
                            <input type="text" name="buy_lr_result" id="buy_lr_result" value="<?php echo $obj->buy_lr_result?>" />
                        </label>
                        
                        
                        <label for="currency">ค่าเงิน:
                            <input type="text" name="currency" id="currency" value="<?php echo $obj->currency?>" />
                        </label>
                        
                        
                        <label for="currency_sig">สัญลักษณ์:
                            <input type="text" name="currency_sig" id="currency_sig" value="<?php echo $obj->currency_sig?>" />
                        </label>
                        
                        <input type="submit" value="<?php echo _ADMIN_BUTTON_EDIT;?>" name="submit">
                        <?php
                        if($_SESSION['process']==='save')
                        {
                            echo '<span>บันทึกข้อมูลเรียบร้อยค่ะ</span>';
                            $_SESSION['process'] = '';
                        }
                        ?>
                    </form>
                    </div>
                </td>
            </tr>
        </table>
        </td>
    </tr>
</table>
<?php
}
else if($option==='update_exchange')
{
    $sell_lr        = htmlspecialchars($_POST['sell_lr'], ENT_QUOTES);
    $sell_lr_result = htmlspecialchars($_POST['sell_lr_result'], ENT_QUOTES);
    $buy_lr         = htmlspecialchars($_POST['buy_lr'], ENT_QUOTES);
    $buy_lr_result  = htmlspecialchars($_POST['buy_lr_result'], ENT_QUOTES);
    $currency       = htmlspecialchars($_POST['currency'], ENT_QUOTES);
    $currency_sig   = htmlspecialchars($_POST['currency_sig'], ENT_QUOTES);
    
    $db->update_db(TB_EXCHANGE,array(
        "sell_lr" => $sell_lr,
        "sell_lr_result" => $sell_lr_result,
        "buy_lr" => $buy_lr,
        "buy_lr_result" => $buy_lr_result,
        "currency" => $currency,
        "currency_sig" => $currency_sig
    )," id = 1");
    $_SESSION['process'] = 'save';
    redirect('index.php?name=admin&file=exchange');
}
else if($option==='users')
{
?>
<style type="text/css">
    .tr_header{
        text-align: center;
        font-weight: bold;
        background-color: #F7F7F7;
    }
    .div_header{
        font-size: 18px;
    }
    .tr_details:hover{
        background-color: #FFF0DF;
    }
</style>
<table cellSpacing=0 cellPadding=0 width=820 border=0>
    <tr>
        <td width="10" vAlign=top>
            <img src="images/fader.gif" border=0>
        </td>
        <td width="810" vAlign=top>
            <img src="images/topfader.gif" border=0><br/>
        <!-- Admin -->
        <img src="images/menu/textmenu_admin.gif" border="0"><br/>
        <table width="800" align=center cellSpacing=0 cellPadding=0 border=0>
            <tr>
                <td height="1" class="dotline"></td>
            </tr>
            <tr>
                <td>
                    <b>
                        <img src="images/icon/plus.gif" border="0" align="absmiddle">
                        <a href="?name=admin&file=main">
                            <?php echo _ADMIN_GOBACK;?>
                        </a>
                    </b><br/>
                    <div id="form_buy">
                        <div class="div_header">
                            <p>รายชื่อผู้สั่งซื้อ LR</p>
                        </div>
                        <table width="100%" class="grids">
                            <tr class="tr_header">
                                <td width="5%">
                                    <p>ID</p>
                                </td>
                                <td>
                                    <p>ชื่อผู้ใช้งาน</p>
                                </td>
                                <td>
                                    <p>เลขที่ LR</p>
                                </td>
                                <td width="15%">
                                    <p>จำนวนที่สั่งซื้อ</p>
                                </td>
                                <td width="15%">
                                    <p>ราคา</p>
                                </td>
                                <td width="15%">
                                    <p>สถานะการโอน</p>
                                </td>
                            </tr>
                            <?php
                            $sql = "SELECT *"
                                ." FROM web_buy_lr ORDER BY id ASC";
                            $res = mysql_query($sql);
                            while($obj = mysql_fetch_object($res))
                            {
                            ?>
                            <tr class="tr_details">
                                <td align="center"><p><?php echo $obj->id?></p></td>
                                <td><p><?php echo $obj->username?></p></td>
                                <td><p><?php echo $obj->lr_number?></p></td>
                                <td width="15%" align="right"><p><?php echo $obj->lr_amount?></p></td>
                                <td width="15%" align="right"><p><?php echo $obj->lr_pay?></p></td>
                                <td width="15%" align="center">
                                    <p>
                                        <?php
                                        if($obj->confirm==='0')
                                        {
                                            echo '<img src="images/publish_x.png">';
                                        }
                                        else
                                        {
                                            echo '<img src="images/tick.png">';
                                        }
                                        ?>
                                    </p>
                                </td>
                            </tr>
                            <?php
                            }
                            ?>
                        </table>
                    </div>
                    
                    <div id="form_sell">
                        <div class="div_header">
                            <p>รายชื่อผู้ขายเหรียญ LR</p>
                        </div>
                        <table width="100%" class="grids">
                            <tr class="tr_header">
                                <td width="5%">
                                    <p>ID</p>
                                </td>
                                <td>
                                    <p>ชื่อผู้ใช้งาน</p>
                                </td>
                                <td>
                                    <p>เลขที่ LR</p>
                                </td>
                                <td width="15%">
                                    <p>จำนวนที่สั่งซื้อ</p>
                                </td>
                                <td width="15%">
                                    <p>ราคา</p>
                                </td>
                                <td width="15%">
                                    <p>สถานะการโอน</p>
                                </td>
                            </tr>
                            <?php
                            $sql = "SELECT *"
                                ." FROM web_sell_lr ORDER BY id ASC";
                            $res = mysql_query($sql);
                            while($obj = mysql_fetch_object($res))
                            {
                            ?>
                            <tr class="tr_details">
                                <td align="center"><p><?php echo $obj->id?></p></td>
                                <td><p><?php echo $obj->username?></p></td>
                                <td><p><?php echo $obj->lr_customer_account?></p></td>
                                <td width="15%" align="right"><p><?php echo $obj->lr_customer?></p></td>
                                <td width="15%" align="right"><p><?php echo $obj->money_receive?></p></td>
                                <td width="15%" align="center">
                                    <p>
                                        <?php
                                        if($obj->confirm==='0')
                                        {
                                            echo '<img src="images/publish_x.png">';
                                        }
                                        else
                                        {
                                            echo '<img src="images/tick.png">';
                                        }
                                        ?>
                                    </p>
                                </td>
                            </tr>
                            <?php
                            }
                            ?>
                        </table>
                    </div>
                </td>
            </tr>
        </table>
        </td>
    </tr>
</table>
<?php
}
?>